package com.xinghai.web.controller.dingtalk;

import com.xinghai.common.annotation.Log;
import com.xinghai.common.core.controller.BaseController;
import com.xinghai.common.core.domain.AjaxResult;
import com.xinghai.common.core.page.TableDataInfo;
import com.xinghai.common.enums.BusinessType;
import com.xinghai.common.exception.ServiceException;
import com.xinghai.common.utils.poi.ExcelUtil;
import com.xinghai.system.domain.XhVehicleInfoApplyRecord;
import com.xinghai.system.service.IXhVehicleInfoApplyRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 用车申请实例任务Controller
 * 
 * @author smy
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/vehicle/apply/record")
public class XhVehicleInfoApplyRecordController extends BaseController
{
    @Autowired
    private IXhVehicleInfoApplyRecordService XhVehicleInfoApplyRecordService;

    /**
     * 查询用车申请实例任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(XhVehicleInfoApplyRecord XhVehicleInfoApplyRecord)
    {
        startPage();
        List<XhVehicleInfoApplyRecord> list = XhVehicleInfoApplyRecordService.list(XhVehicleInfoApplyRecord);
        return getDataTable(list);
    }

    /**
     * 导出用车申请实例任务列表
     */
    @Log(title = "用车申请实例任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XhVehicleInfoApplyRecord XhVehicleInfoApplyRecord)
    {
        List<XhVehicleInfoApplyRecord> list = XhVehicleInfoApplyRecordService.list(XhVehicleInfoApplyRecord);
        ExcelUtil<XhVehicleInfoApplyRecord> util = new ExcelUtil<XhVehicleInfoApplyRecord>(XhVehicleInfoApplyRecord.class);
        util.exportExcel(response, list, "用车申请实例任务数据");
    }

    /**
     * 获取用车申请实例任务详细信息
     */
    @GetMapping("/getInfo")
    public AjaxResult getInfo(Long id)
    {
        return success(XhVehicleInfoApplyRecordService.getInfo(id));
    }

    /**
     * 新增用车申请实例任务
     */
    @Log(title = "用车申请实例任务", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody XhVehicleInfoApplyRecord XhVehicleInfoApplyRecord)
    {
        return toAjax(XhVehicleInfoApplyRecordService.insert(XhVehicleInfoApplyRecord));
    }

    /**
     * 修改用车申请实例任务
     */
    @Log(title = "用车申请实例任务", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody XhVehicleInfoApplyRecord XhVehicleInfoApplyRecord)
    {
        return toAjax(XhVehicleInfoApplyRecordService.update(XhVehicleInfoApplyRecord));
    }

    /**
     * 删除用车申请实例任务
     */
    @Log(title = "用车申请实例任务", businessType = BusinessType.DELETE)
	@PostMapping("/delete")
    public AjaxResult delete(Long id)
    {
        return toAjax(XhVehicleInfoApplyRecordService.delete(id));
    }


    /**
     * 批量删除用车申请实例任务
     */
    @Log(title = "用车申请实例任务", businessType = BusinessType.DELETE)
    @PostMapping("/deleteBatch")
    public AjaxResult deleteBatch(Long[] ids)
    {
        return toAjax(XhVehicleInfoApplyRecordService.deleteBatch(ids));
    }

    /**
     * 导入用车申请实例任务模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<XhVehicleInfoApplyRecord> util = new ExcelUtil<XhVehicleInfoApplyRecord>(XhVehicleInfoApplyRecord.class);
        util.importTemplateExcel(response, "用车申请实例任务数据模板");
    }


    /**
     * 导入用车申请实例任务
     */
    @Log(title = "用车申请实例任务管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file)
    {
        ExcelUtil<XhVehicleInfoApplyRecord> util = new ExcelUtil<XhVehicleInfoApplyRecord>(XhVehicleInfoApplyRecord.class);
        List<XhVehicleInfoApplyRecord> XhVehicleInfoApplyRecordList = null;
        try {
            XhVehicleInfoApplyRecordList = util.importExcel(file.getInputStream());
        } catch (IOException e) {
            throw new ServiceException("导入数据失败");
        }
        return success(XhVehicleInfoApplyRecordService.importData(XhVehicleInfoApplyRecordList));
    }

    /**
     * 根据vehicleId查询用车申请实例任务列表
     */
    @GetMapping("/{vehicleId}")
    public TableDataInfo list(@PathVariable("vehicleId") Long vehicleId)
    {
        startPage();
        List<XhVehicleInfoApplyRecord> list = XhVehicleInfoApplyRecordService.getInfoByVehicleId(vehicleId);
        return getDataTable(list);
    }
}
